<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <ui:composition template="/shared/_layout.xhtml">
        <ui:define name="title">
            <h:outputText value="#{lang._shopping_index_title}"/>
        </ui:define>
        <ui:define name="css">
            <h:outputStylesheet name="form.css" library="css" />
            <h:outputStylesheet name="shopping/index.css" library="css" />
        </ui:define>
        <ui:define name="content">
            <article>
                <h1>
                    <h:outputText value="#{lang._shopping_index_shopping}"/>
                </h1>
                <c:choose>
                    <c:when test="#{shoppingCart.hasItems()}">
                        <section>
                            <h2>
                                <h:outputText value="#{lang._shopping_index_books_list}"/>
                            </h2>
                            
                                        <p>
                                            <h:messages errorClass="errorMessage" infoClass="infoMessage"
                                                        warnClass="warnMessage"/>
                                        </p>
                            <h:dataTable value="#{shoppingCart.items}" var="entry">
                                <h:column>
                                    <f:facet name="header"></f:facet>
                                    <h:graphicImage library="img/books" name="#{entry.article.idArticles.image}" height="75" width="50"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        Nom
                                    </f:facet>
                                    <h:outputText value="#{entry.article.idArticles.name}"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        Prix
                                    </f:facet>
                                    <h:outputText value="#{entry.article.idArticles.price}€"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        Quantité
                                    </f:facet>
                                    <h:form>
                                        <p>
                                            <h:inputText label="Quantité" value="#{entry.quantity}" maxlength="2" size="3"/>
                                            <h:outputText value="&#160;"/>
                                            <h:commandButton value="#{lang._shopping_index_update}" action="#{shoppingCart.update(entry)}"/>
                                        </p>
                                    </h:form>
                                </h:column>
                            </h:dataTable>
                            <p id="subtotal">
                                <h:outputText value="#{lang._shopping_index_subtotal}"/>
                                <h:outputText value="#{shoppingCart.subtotal}€"/>
                                <br/>
                                <h:outputText value="#{lang._shopping_index_subtotal_ttc}"/>
                                <h:outputText value="#{shoppingCart.subtotalTTC}€"/>
                            </p>
                        </section>
                        <c:if test="#{account.isLogged == true}">
                            <section>
                                <h2>
                                    <h:outputText value="#{lang._shopping_index_books_list}"/>
                                </h2>
                                <p>
                                    <h:outputText value="#{lang._shopping_index_shopping_logged}"/>
                                    <h:link outcome="/shopping/validation/index" value="#{lang._shopping_index_shopping_validation}"/>
                                </p>
                            </section>
                        </c:if>
                    </c:when>
                    <c:otherwise>
                        <section>
                            <h2>
                                <h:outputText value="#{lang._shopping_index_shopping_empty_title}"/>
                            </h2>
                            <p>
                                <h:outputText value="#{lang._shopping_index_shopping_empty}"/>
                            </p>
                        </section>
                    </c:otherwise>
                </c:choose>
            </article>
        </ui:define>
    </ui:composition>
</html>

